//
//  WelcomeViewController.swift
//  dwdWb
//
//  Created by Dengdwd on 15/10/10.
//  Copyright © 2015年 dwd. All rights reserved.
//

import UIKit
import SDWebImage
class WelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setUpUI()
        let account = UserAcount.loadUserData()
        let urlString = account?.avatar_large ?? ""
        iconView.sd_setImageWithURL(NSURL(string: urlString))
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let h = -(UIScreen.mainScreen().bounds.height + bottomCons!.constant)
        bottomCons?.constant = h
        nameLabel.alpha = 0
        UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity:10, options:[], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (Bool) -> Void in
            UIView.animateWithDuration(0.8, animations: { () -> Void in
                self.nameLabel.alpha = 1
                }, completion: { (Bool) -> Void in
                    NSNotificationCenter.defaultCenter().postNotificationName(DWDSwiftRootviewControllerNotification, object: nil)
            })
        }
    }
    private var bottomCons: NSLayoutConstraint?
    private func setUpUI() {
    
        view.addSubview(backgroudView)
        view.addSubview(nameLabel)
        view.addSubview(iconView)
        backgroudView.ff_Fill(view)
        let cons = iconView.ff_AlignInner(type: ff_AlignType.BottomCenter, referView: view, size: CGSize(width: 90, height: 90), offset: CGPoint(x: 0, y: -200))
        self.bottomCons = iconView.ff_Constraint(cons, attribute: NSLayoutAttribute.Bottom)
        nameLabel.ff_AlignHorizontal(type:ff_AlignType.BottomCenter, referView: iconView, size: nil, offset: CGPoint(x: 0, y: 25))
        
    }

    private var backgroudView : UIImageView = {
    
        let bv = UIImageView(image: UIImage(named: "ad_background"))
        
        return bv
    }()
    private var iconView : UIImageView = {
        
        let iv = UIImageView(image: UIImage(named: "avatar_default_big"))
        iv.layer.cornerRadius = 45
        iv.layer.masksToBounds = true
        return iv
    }()

    private var nameLabel: UILabel = {
    
        let nl = UILabel()
        nl.text = "欢迎回来"
        return nl
    }()
    
}
